/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.image.ParticleAnalysisReport;

/**
 *
 * @author Matt
 */
public class Target {

    private int width;
    private int height;
    private double ratio;
    private boolean possTarget;
    private int x;
    private int y;
    private ParticleAnalysisReport report;

    private static final double actRatio = 0.716;
    private static final double allowance = 0.15;

    public Target(ParticleAnalysisReport r) {
        this.report = r;
        this.width = r.boundingRectWidth;
        this.height = r.boundingRectHeight;
        if(this.width != 0 && this.height != 0) {
            this.ratio = (this.height * 1.0) / (this.width * 1.0);
        } else {
            this.ratio = 0;
        }
        if(this.ratio <= actRatio * (1 + allowance) && this.ratio >= actRatio * (1 - allowance)) {
            this.possTarget = true;
        } else {
            this.possTarget = false;
        }
        this.x = r.center_mass_x;
        this.y = r.center_mass_y;
    }

    public int getX() {
        return this.x;
    }

    public int getY() {
        return this.y;
    }

    public double getRatio() {
        return this.ratio;
    }

    public boolean isTarget() {
        return this.possTarget;
    }

    public boolean vertAlign(Target t) {
        if(t.getY() <= this.y * (1 + allowance) && t.getY() >= this.y * (1 - allowance)) {
            return true;
        } else {
            return false;
        }
    }

    public boolean horzAlign(Target t) {
        if(t.getX() <= this.x * (1 + allowance) && t.getX() >= this.x * (1 - allowance)) {
            return true;
        } else {
            return false;
        }
    }

}
